#include "rclcpp/rclcpp.hpp"
#include "base_interfaces_demo/msg/student.hpp"
using namespace std::chrono_literals;
using base_interfaces_demo::msg::Student;
class TalkerStu :public rclcpp::Node
{
public:
    TalkerStu():Node("talker_stu_node_cpp")
    {
        RCLCPP_INFO(this->get_logger(),"发布节点已创建");
        publisher_=this->create_publisher<Student>("chatter",10);
        timer_=this->create_wall_timer(1s,std::bind(&TalkerStu::on_timer,this));
    }
private:
    void on_timer()
    {
        auto message=Student();
        message.name="大帅笔";
        message.age=count++;
        message.height=1.70;
        RCLCPP_INFO(this->get_logger(),"发布的消息是：姓名：%s,年龄：%d岁,身高：%.2f米",message.name.c_str(),message.age,message.height);
        publisher_->publish(message);
    }

    std::shared_ptr<rclcpp::Publisher<Student>>publisher_;
    std::shared_ptr<rclcpp::TimerBase>timer_;
    size_t count;
};
int main(int argc,char *argv[])
{
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<TalkerStu>());
    rclcpp::shutdown();
}